package com.app.service.impl;

import com.app.mapper.PersonCheckMapper;
import com.app.mapper.PersonResumeMapper;
import com.app.model.PersonCheckModel;
import com.app.model.PersonModel;
import com.app.model.PersonResumeModel;
import com.app.service.PersonCheckService;
import com.app.service.PersonResumeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Primary
public class PersonCheckServiceImpl implements PersonCheckService {
    @Autowired
    PersonCheckMapper personCheckMapper;


    @Override
    public List<PersonCheckModel> getCheckList(int personId) {
        QueryWrapper<PersonCheckModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "person_id", "year", "check_result", "create_time", "update_time").eq("person_id", personId).orderByDesc("year");
        List<PersonCheckModel> checkModelList = personCheckMapper.selectList(queryWrapper);
        return checkModelList;
    }

    @Override
    public List<PersonCheckModel> listExport() {
        QueryWrapper<PersonCheckModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id", "person_id", "year", "check_result", "create_time", "update_time");
        List<PersonCheckModel> checkModelList = personCheckMapper.selectList(queryWrapper);
        return checkModelList;
    }

    @Override
    public List<PersonCheckModel> getPersonByDepAndYear(List<Integer> idList, List<String> yearList) {
        QueryWrapper<PersonCheckModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select();
        if (idList == null || idList.isEmpty()) {
            queryWrapper.select();
        } else {
            queryWrapper.in("person_id", idList);
            queryWrapper.in("year", yearList);
        }
        List<PersonCheckModel> checkModelList = personCheckMapper.selectList(queryWrapper);
        return checkModelList;
    }

    @Override
    public PersonCheckModel selectCheckByIdAndYear(Integer personId, Integer year) {
        QueryWrapper<PersonCheckModel> queryWrapper = new QueryWrapper<>();
        queryWrapper.select().eq("person_id", personId).eq("year", year);
        PersonCheckModel model = personCheckMapper.selectOne(queryWrapper);
        return model;
    }

    @Override
    public void update(PersonCheckModel model) {
        personCheckMapper.updateById(model);
    }

    @Override
    public void insert(PersonCheckModel model) {
        personCheckMapper.insert(model);
    }

    @Override
    public void delete(int id) {
        personCheckMapper.deleteById(id);
    }


}
